#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/1/15 18:00
# @Author : 闫峰
# @File    : view.py
import datetime
import json
from urllib import parse
from flask import request, Response
from util.otherutils.functions_control import randomint, get_uuid
from util import handler_request_log
from util.mongodb_utils import MongoDBLink
from util.redis_control.redis_operations import RedisOperator
user = parse.quote_plus("viviu")
passwd = parse.quote_plus("viu@1234")
modb_client = MongoDBLink(
    uri=f'mongodb://{user}:{passwd}@10.86.3.113:27017/?authSource=admin',
    dbname='sit_charge_mock_data', coll_name='sit_charge_mock_data')
redis_client = RedisOperator()


def v1_third_getchargeid():
    request_id = str(get_uuid())
    cid = str(randomint(6))

    resp_json = {
        "ret": {
            "code": 0,
            "msg": f"ok",
            "request_id": request_id
        },
        "charging_info":{
            "cid": cid,
            "left_duration": 300

        }

    }
    resp_str = json.dumps(resp_json)
    response = Response(resp_str, status=200, mimetype='application/json')
    handler_request_log(request,200,resp_json,modb_client,True)
    return response


def v1_third_begincharging():
    request_id = str(get_uuid())
    cid = str(randomint(6))
    resp_json = {
        "ret": {
            "code": 0,
            "msg": f"ok",
            "request_id": request_id
        },
        "charging_info":{
            "cid": cid,
            "left_duration": 300

        }

    }
    resp_str = json.dumps(resp_json)
    response = Response(resp_str, status=200, mimetype='application/json')
    handler_request_log(request,200,resp_json,app.config['modb_client'],True)
    return response


def v1_third_endcharging():
    request_id = str(get_uuid())
    cid = str(randomint(6))
    resp_json = {
        "ret": {
            "code": 0,
            "msg": f"ok",
            "request_id": request_id
        }

    }
    resp_str = json.dumps(resp_json)
    response = Response(resp_str, status=200, mimetype='application/json')
    handler_request_log(request,200,resp_json,app.config['modb_client'],True)
    return response


def get_scheduling_policy():
    resp_json = {"ret":{"code":0},"body": {"queue_level":1233,"rset_id":45676}}
    resp_str = json.dumps(resp_json)
    response = Response(resp_str, status=200, mimetype='application/json')
    handler_request_log(request,200,resp_json,app.config['modb_client'],True)
    return response